home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / xlib03.zip / DEMO2.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  5KB  |  174 lines

  1. /*************************************************************************
  2.  
  3. DEMO 2
  4.  
  5. Demonstrates the speed difference between compiled bitmap and conventional
  6. masked planar bitmap blits.
  7.  
  8. **************************************************************************/
  9.  
  10.  
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <conio.h>
  15. #include <ctype.h>
  16. #include <alloc.h>
  17. #include <dos.h>
  18. #include "xlib.h"
  19. #include "xcbitmap.h"
  20. #include "xpbitmap.h"
  21. #include "xbmtools.h"
  22. #include  "xtext.h"
  23. #include  "xrect.h"
  24.  
  25. /* Macro to make pointer parameters model independent */
  26. #define FARPTR(x) (MK_FP(FP_SEG(x),FP_OFF(x)))
  27.  
  28. char turtle[] = {
  29.     20,30,
  30. /*  |      .       |       .      |       .      |      .       */
  31.     8,14, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  32.     8, 2,14, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33.     8, 2, 2, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34.     8, 0, 2,14, 0, 0,14,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  35.     8, 0, 2, 5, 0, 4, 4, 4, 4,14,14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36.     8, 0, 2, 2, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0, 0, 0, 0,
  37.     0, 0, 2, 4, 4, 4, 0, 4, 4, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  38.     0, 0, 2, 4, 4, 4, 0, 0, 0, 0, 4, 4,14, 0, 0, 0, 0, 0, 0, 0,
  39.     0, 0, 0, 0, 4, 0, 4, 4, 4, 0, 0, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  40.     0, 0, 0, 4, 0, 4, 4, 4, 0, 4, 4, 4, 0,14, 0, 0, 2, 2, 0, 0,
  41.     0, 0, 0, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 4, 2, 2, 2, 2, 0, 0,
  42.     0, 0, 0, 4, 4, 4, 0, 4, 4, 0, 4, 4, 0, 4,14, 2, 2, 2, 0, 0,
  43.     0, 0, 0, 4, 4, 4, 0, 0, 0, 4, 4, 0, 4, 0, 0, 2, 2, 0, 0, 0,
  44.     0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4,14, 2, 0, 0, 0, 0,
  45.     0, 0, 2, 2, 0, 4, 4, 4, 4, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0,
  46.     2, 2, 2, 2, 4, 0, 0, 4, 4, 0, 4, 4, 0, 4,14, 0, 0, 0, 0, 0,
  47.     0, 2, 2, 0, 4, 4, 4, 0, 0, 4, 4, 0, 4, 0, 2, 0, 0, 0, 0, 0,
  48.     0, 0, 0, 0, 0, 4, 4, 0, 4, 4, 4, 0, 4, 4, 2,14, 0, 0, 0, 0,
  49.     0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 4, 0, 2, 2,14,14, 0, 0,
  50.     0, 0, 0, 0, 0, 0, 0, 4, 4, 0, 0, 4, 4, 2, 2, 2, 2, 2,14, 0,
  51.     0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 5,14, 0,
  52.     0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 2, 2, 0, 0, 2, 2, 2, 0, 2,14,
  53.     0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,14,
  54.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2,
  55.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0,
  56.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  57.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  58.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0,
  59.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
  60.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  61.     };
  62.  
  63.  
  64. char far *pbm;
  65. char far *newfnt;
  66.  
  67. char far *
  68. AllocatedSprite(int width, int height, int logical_width, char far * bitmap)
  69. {
  70.     char far * result;
  71.     int size;
  72.  
  73.     pbm = farmalloc(width * height + 2);
  74.     x_bm_to_pbm(bitmap,pbm);
  75.  
  76.     result = farmalloc((width * height * 7) / 2 + 25);
  77.     if (result == 0)
  78.         return(0);
  79.     size = x_compile_bitmap(logical_width, bitmap, result);
  80.  
  81.     return farrealloc(result, size);
  82. }
  83.  
  84.  
  85. void load_user_fonts(){
  86.   FILE *f;
  87.   int i; char c;
  88.   f=fopen("6x8b.fnt","rb");
  89.   newfnt = farmalloc(256*8+4);
  90.   for (i=0;i<256*8+4;i++){
  91.     fread(&c,1,1,f);
  92.     *(newfnt+i)=c;
  93.   }
  94.   fclose(f);
  95.   x_text_init();
  96.   x_register_userfont(newfnt);
  97.   x_set_font(2);
  98. }
  99.  
  100. void
  101. main()
  102. {
  103.     int i,j;
  104.     double ratio;
  105.     struct time pbm_t0,pbm_t1,cbm_t0,cbm_t1;
  106.     long pbm_ticks,cbm_ticks;
  107.     char far * TurtleSprite;
  108.  
  109.     x_set_mode(7,360);
  110.  
  111.  
  112.     TurtleSprite = AllocatedSprite(20, 30, 90,FARPTR(turtle));
  113.  
  114.     load_user_fonts();
  115.     x_bgprintf(0,0,0,14,0,
  116.       "This is a quick demo to show the speed difference between");
  117.     x_bgprintf(0,8,0,14,0,
  118.       "compiled bitmaps and Planar Bitmaps. Here are is the bitmap:");
  119.  
  120.     x_put_cbitmap(140, 18, 0, TurtleSprite);
  121.  
  122.     x_bgprintf(0,48,0,14,0,
  123.       "Press a key to start with PLANAR BITMAP demo");
  124.  
  125.     getch();
  126.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  127.  
  128.  
  129.     gettime(&pbm_t0);
  130.     for (j=0;j<(ScrnPhysicalHeight/30);j++)
  131.       for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  132.     x_put_masked_pbm(i*20, j*30, 0, pbm);
  133.     gettime(&pbm_t1);
  134.     pbm_ticks = (((long)pbm_t1.ti_hund
  135.         +((long)pbm_t1.ti_sec*100)
  136.         +((long)pbm_t1.ti_min*6000)) -
  137.         (((long)pbm_t0.ti_hund
  138.         +((long)pbm_t0.ti_sec*100)
  139.         +((long)pbm_t0.ti_min*6000))));
  140.  
  141.  
  142.     x_bgprintf(0,0,0,14,0,
  143.       "Now Press a key to start with COMPILED BITMAP demo");
  144.  
  145.     getch();
  146.     x_rect_fill(0,0,ScrnPhysicalPixelWidth,ScrnPhysicalHeight,0,0);
  147.  
  148.     gettime(&cbm_t0);
  149.     for (j=0;j<(ScrnPhysicalHeight/30);j++)
  150.       for (i=0;i<(ScrnPhysicalPixelWidth/20);i++)
  151.     x_put_cbitmap(i*20, j*30, 0, TurtleSprite);
  152.     gettime(&cbm_t1);
  153.     cbm_ticks = (((long)cbm_t1.ti_hund
  154.         +((long)cbm_t1.ti_sec*100)
  155.         +((long)cbm_t1.ti_min*6000)) -
  156.         (((long)cbm_t0.ti_hund
  157.         +((long)cbm_t0.ti_sec*100)
  158.         +((long)cbm_t0.ti_min*6000))));
  159.     ratio = pbm_ticks*(double)1.0/cbm_ticks;
  160.  
  161.     x_set_font(1);
  162.     x_bgprintf(0,ScrnPhysicalHeight-22,0,14,0,
  163.       "secs/100 PBM=%ld CBM=%ld RATIO %4.1lf:1",pbm_ticks,cbm_ticks,
  164.       ratio);
  165.     x_set_font(2);
  166.     x_bgprintf(0,ScrnPhysicalHeight-8,0,14,0,
  167.       "Timing is rough but still,  quite impressive ! ");
  168.  
  169.  
  170.     getch();
  171.     x_text_mode();
  172. }
  173.  
  174.